using System;
using System.Threading;
using System.Threading.Tasks;

namespace RTMP.SimpleClient.Messages
{
    /// <summary>
    /// 消息转换器接口
    /// </summary>
    public interface IMessageConverter
    {
        /// <summary>
        /// 将原始消息数据转换为强类型对象
        /// </summary>
        /// <param name="rawData">原始消息数据</param>
        /// <param name="targetType">目标类型</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>转换后的对象</returns>
        Task<object?> ConvertAsync(byte[] rawData, Type targetType, CancellationToken cancellationToken = default);

        /// <summary>
        /// 将原始消息数据转换为指定类型的对象
        /// </summary>
        /// <typeparam name="T">目标类型</typeparam>
        /// <param name="rawData">原始消息数据</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>转换后的对象</returns>
        Task<T?> ConvertAsync<T>(byte[] rawData, CancellationToken cancellationToken = default) where T : class;

        /// <summary>
        /// 检查是否支持指定类型的转换
        /// </summary>
        /// <param name="targetType">目标类型</param>
        /// <returns>是否支持</returns>
        bool CanConvert(Type targetType);
    }
}